package com.lzm.listendemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lzm.listendemo.R;
import com.lzm.listendemo.bean.Article;
import com.lzm.listendemo.bean.HotKey;

import java.util.List;

public class HotKeyAdapter extends RecyclerView.Adapter<HotKeyAdapter.ViewHolder> {
    List<HotKey> items;
    private onItemClick click = null;
    public HotKeyAdapter(List<HotKey> items) {
        this.items = items;
    }

    @NonNull
    @Override
    public HotKeyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HotKeyAdapter.ViewHolder holder, int position) {
        HotKey item = items.get(position);
        holder.text.setText(item.getName());
    }

    public interface onItemClick{
        void onClick(View view,Article article);
    }


    @Override
    public int getItemCount() {
        return items.size();
    }

    public void setList(List<HotKey> hotKeys) {
        this.items = hotKeys;
        notifyDataSetChanged();
    }

    public void setItemOnClick(onItemClick onClick) {
        this.click = onClick;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView text;

        public ViewHolder(View view) {
            super(view);
            text = (TextView) view.findViewById(R.id.text);
        }

    }

}